package com.bdzl.biz.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class test {
    public static void main(String[] args) {
            try {
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date now = df.parse("2021-05-20 10:45:49");//当前时间
                Date date = df.parse("2021-05-19 16:11:05");//过去
                long l = now.getTime() - date.getTime();
                long day = l / (24 * 60 * 60 * 1000);
                long hour = (l / (60 * 60 * 1000) - day * 24);
                long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
                long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
                Integer i = Math.toIntExact(l/1000);
                System.out.println(i+"----" + day + "天" + hour + "小时" + min + "分" + s + "秒");
            } catch (Exception e) {

            }

    }
}
